import { Application } from 'egg';
import * as pageFindPlugin from 'mongoose-paginate';
import { sourceType } from '../constants/dictionaries';
export default (app: Application) => {
  const mongoose = app.mongoose;
  const ObjectId = mongoose.Schema.Types.ObjectId;
  const schema = new mongoose.Schema({
    producId: ObjectId,
    type: {
      type: String,
      enum: sourceType, // 旅划算，直营，联联
      default: 'youbang',
    },
    quantity: Number, // 库存
    price: Number, // 价格
    skuText: String, // sku文字
    rebateMoney: Number, // 佣金
    saledNum: Number, // 销量
    sourceId: Number, // 供应商skuId
    status: {
      type: Number,
      enum: [ 0, 1 ], // 0 正常 1 下架
      default: 0,
    },
  }, {
      timestamps: { createdAt: true, updatedAt: true },
  });

  schema.index({ });
  schema.plugin(pageFindPlugin, {});
  return mongoose.model('Preferentialnearly', schema, 'preferentialnearly');
};
